package edu.sias.course.controller;

import java.util.List;

import edu.sias.common.core.controller.BaseController;
import edu.sias.common.core.domain.AjaxResult;
import edu.sias.common.core.page.TableDataInfo;
import edu.sias.course.domain.pojo.CourseContent;
import edu.sias.course.service.ICourseContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 课程内容Controller
 *
 * @author liu
 * @date
 */
@RestController
@RequestMapping("/course/content")
public class CourseContentController  extends BaseController {

    @Autowired
    private ICourseContentService courseContentService;

    /**
     * 查询课程内容列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CourseContent courseContent) {
        startPage();
        List<CourseContent> list = courseContentService.listCourseContent(courseContent);
        return getDataTable(list);
    }

    /**
     * 获取课程内容详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult get(@PathVariable("id") Long id) {
        return success(courseContentService.getCourseContentById(id));
    }

    /**
     * 新增课程内容
     */
    @PostMapping
    public AjaxResult add(@RequestBody CourseContent courseContent) {
        System.out.println(courseContent.getCatalogId());
        courseContent.setCatalogId(1);
        System.out.println(courseContent.getCatalogId());

        return toAjax(courseContentService.addCourseContent(courseContent));
    }

    /**
     * 修改课程内容
     */
    @PutMapping
    public AjaxResult update(@RequestBody CourseContent courseContent) {
        return toAjax(courseContentService.updateCourseContent(courseContent));
    }

    /**
     * 删除课程内容
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        return toAjax(courseContentService.removeCourseContentById(id));
    }
}
